from typing import List
class Solution:
    def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int:
        directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        grid = [[""] * n for _ in range(m)]
        for g in guards:
            grid[g[0]][g[1]] = "G"
        for w in walls:
            grid[w[0]][w[1]] = "W"
        for i in range(m):
            for j in range(n):
                if grid[i][j] == "G":
                    for dx, dy in directions:
                        x, y = i + dx, j + dy
                        while 0 <= x < m and 0 <= y < n and grid[x][y] != "W" and grid[x][y] != "G":
                            grid[x][y] = "BG"
                            x += dx
                            y += dy
        return sum(grid[i][j] == "" for i in range(m) for j in range(n))